using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Resources;
using System.Drawing.Imaging;
using System.Drawing;
using System.Reflection;
using System.Globalization;


namespace masterCard
{
    enum CardType { TWO = 2, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE };
    enum CardSuit { Clubs = 1, Diamonds, Heart, Spade };
    
    class Card
    {
        private CardType m_eType;
        private CardSuit m_eSuit;
        public Card(CardSuit cs, CardType cr)
        {
            m_eType = cr;
            m_eSuit = cs;
        }
        public Card(string s)
        {
            string[] tok = s.Split('_');
            if (tok.Length == 2)
            {
                m_eType = getCardType(tok[1]);
                m_eSuit = getCardSuit(tok[0]);
            }

        }

        private CardSuit getCardSuit(string p)
        {
            CardSuit temp = CardSuit.Clubs;
            foreach (CardSuit cs in CardSuit.GetValues(typeof(CardSuit)))
            {
                if (cs.ToString() == p)
                {
                    temp = cs;
                    break;
                }
            }
            return temp;

        }

        private CardType getCardType(string p)
        {
            CardType temp = CardType.TWO;
            foreach (CardType ct in CardType.GetValues(typeof(CardType)))
            {
                if (ct.ToString() == p)
                {
                    temp = ct;
                    break;
                }
            }
            return temp;

        }

        public CardType GetCardType()
        {
            return m_eType;
        }

        public CardSuit GetCardSuit()
        {
            return m_eSuit;
        }

        public string GetImageName()
        {
            return GetSymbolText();//+ ;".gif"; ;
        }

        public string GetSymbolText()
        {
            return m_eType.ToString() + "_" + m_eSuit.ToString();
        }

    };
    class CardPack
    {
        public const int nPackSize = 52;
        private int m_nCurrentIndex;
        public Card GetCard()
        {
            return m_cCardPack[m_nCurrentIndex++];
        }

        public void ReturnCard(Card card)
        {
            m_cCardPack[m_nCurrentIndex++] = card;
        }
        public void Shuffle()
        {
            m_nCurrentIndex = 0;
        }
        public CardPack()
        {
            m_cCardPack = new Card[nPackSize];
            int i = 0;

            foreach (CardSuit cs in CardSuit.GetValues(typeof(CardSuit)))
            {
                foreach (CardType ct in CardType.GetValues(typeof(CardType)))
                {
                    Card aCard = new Card(cs, ct);
                    m_cCardPack[i++] = (aCard);
                }
            }
        }
        Card[] m_cCardPack;
    };

    //	A shared reference to access images and other resources.
    internal abstract class Resources
    {
        private static ResourceManager imgMgnr;

        static Resources()
        {
            imgMgnr = new ResourceManager("masterCard.cards", Assembly.GetExecutingAssembly());
        }

        public static ResourceManager Images
        {
            get { return imgMgnr; }
        }

        public static Image GetImage(string imageId)
        {
            return (Image)imgMgnr.GetObject(imageId, CultureInfo.InvariantCulture);
        }
    }
}
